package com.only4play.practice;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.annotation.MapperScans;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.web.client.RestTemplate;

/**
 * @author mdy
 * * @date 2024/9/15
 */
@SpringBootApplication
@Slf4j
@MapperScans({
        @MapperScan("com.only4play.practice.template.core.mapper")
})
@ComponentScans({
        // 扫描自定义异常，不然不生效
        @ComponentScan(basePackages = "com.only4play.practice.common.exception"),
        // 扫描自定义配置类，不然不生效
        @ComponentScan(basePackages = "com.only4play.practice.common.config")
})
public class TemplateCoreApp {

    // 使用RestTemplateBuilder来实例化RestTemplate对象，spring默认已经注入了RestTemplateBuilder实例

    /**
     *
     * Spring Boot<=1.3 的版本，使用@Bean注入RestTemplate即可
     * Spring Boot>=1.4 的版本，由于使用了RestTemplateBuilder，所以需要使用@Bean标注该方法
     */
    @Bean
    public RestTemplate restTemplate( RestTemplateBuilder builder) {
        return builder.build();
    }
    public static void main(String[] args) {
        SpringApplication.run(TemplateCoreApp.class, args);
        log.info("TemplateCoreApp start");
    }
}
